use rbatis::{crud, impled, py_sql, RBatis};
use rbatis::executor::Executor;
use crate::domain::dto::project_dto::ProjectPageResponse;
use crate::domain::entity::project_entity::ProjectEntity;

/// ProjectEntity 基础查询
crud!(ProjectEntity {}, "api_project");

#[py_sql("`select count(t.id) from api_project as t where t.biz_id=#{biz_id}`")]
pub async fn count_by_biz_id(rb: &mut dyn Executor, biz_id: u64) -> rbatis::Result<u64> {
    impled!()
}

#[py_sql("`select count(t.id) from api_project as t where t.project_name=#{name}`")]
pub async fn count_by_name(rb: &mut dyn Executor, name: &str) -> rbatis::Result<u64> {
    impled!()
}

#[py_sql("`select `
    `ap.id,`
    `ap.project_name,`
    `ap.project_desc,`
    `ap.biz_id,`
    `(select ab.biz_name from api_biz ab where ab.id = ap.biz_id) as biz_name `
`from api_project ap where 1 = 1 `
if name != '':
    ` and ap.project_name like concat('%', #{name}, '%') `
if biz_id != 0:
    ` and ap.biz_id = #{biz_id} `
` order by ap.project_name asc limit #{size} offset #{num}`")]
pub async fn select_project_page(rb: &mut dyn Executor, num: u64, size: u64, name: Option<String>, biz_id: Option<u64>) -> rbatis::Result<Vec<ProjectPageResponse>> {
    impled!()
}

#[py_sql("`select count(1) from api_project ap where 1 = 1 `
if name != '':
    ` and ap.project_name = #{name} `
if biz_id != 0:
    ` and ap.biz_id = #{biz_id} `")]
pub async fn select_project_count(rb: &mut dyn Executor, name: Option<String>, biz_id: Option<u64>) -> rbatis::Result<u64> {
    impled!()
}

/// select_by_id 使用ID获取数据
#[py_sql("`select * from api_project where id = #{id}`")]
pub async fn select_by_id(rb: &mut RBatis, id: u64) -> rbatis::Result<Option<ProjectEntity>> {
    impled!()
}